﻿<%@ Page Title="Generator" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" Inherits="_Default" validateRequest="false" Codebehind="Generator.aspx.cs" %>


<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/base/jquery-ui.css"
        type="text/css" media="all" />
    <link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
    <link href="Styles/start/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #FinishedText
        {
            width: 602px;
            height: 36px;
        }
    </style>
</asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <script src="Scripts/jquery-1.7.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="Scripts/ui/jquery.ui.core.js"></script>
    <script type="text/javascript" src="Scripts/ui/jquery.ui.widget.js"></script>
    <script type="text/javascript" src="Scripts/ui/jquery.ui.position.js"></script>
    <script type="text/javascript" src="Scripts/ui/jquery.ui.autocomplete.js"></script>
    <%--<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
--%>
    <script src="Scripts/nicEdit.js" type="text/javascript"></script>
    
    
    <style>
	.ui-autocomplete {
		max-height: 300px;
		overflow-y: auto;
		/* prevent horizontal scrollbar */
		overflow-x: hidden;
		/* add padding to account for vertical scrollbar */
		padding-right: 20px;
	}
	/* IE 6 doesn't support max-height
	 * we use height instead, but this forces the menu to always be this tall
	 */
	* html .ui-autocomplete {
		height: 300px;
	}
	</style>  


    <script type="text/javascript">

        var browserName = getBrowserName();

//try to do java before postback
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(InitializeRequest);

        function InitializeRequest(sender, args) {
            $("#<%=HiddenTextArea.ClientID%>").val(nicEditors.findEditor('FinishedText').getContent());
            //alert("postback occured");
        }
       

        var nic;
        bkLib.onDomLoaded(function () {
            try {
                startNicEditor();
                nicEditors.findEditor('FinishedText').setContent($("#<%=HiddenTextArea.ClientID%>").val());  //setting the content from the hidden text area to nicEdit

                //new nicEditor({ fullPanel: false, buttonList: ['fontSize', 'fontFamily', 'forecolor', 'bold', 'italic', 'underline', 'strikethrough', 'left', 'center', 'right'], externalCSS: 'Styles/Site.css', iconsPath: 'img/nicEditorIcons.gif'})
                //.panelInstance('MyTextArea').SetASPNetHiddenField($get("<%=HiddenTextArea.ClientID%>").name);
            }
            catch (ex) { }

        });


        function getBrowserName() {
            var browserName1 = navigator.appName;
            if (browserName1 == "Microsoft Internet Explorer") return "Microsoft Internet Explorer";
            else if (browserName1 == "Opera") return "Opera";
            else if (browserName1 == "Netscape") {
                var stringContainingName = navigator.userAgent;
                if (stringContainingName.match(/Safari/gi) == "Safari") {
                    if (stringContainingName.match(/Chrome/gi) == "Chrome") return "Chrome";
                    else return "Safari";
                }
                else if (stringContainingName.match(/Chrome/gi) == "Chrome") return "Chrome";
                else if (stringContainingName.match(/Firefox/gi) == "Firefox") return "Firefox";
                else return "unknown";
            }
            else return "unknown";
        }

    </script>
    
    <script>
        $(function () {
            var availableTags = [
			"ActionScript",
			"AppleScript",
			"Asp",
			"BASIC",
			"C",
			"C++",
			"Clojure",
			"COBOL",
			"ColdFusion",
			"Erlang",
			"Fortran",
			"Groovy",
			"Haskell",
			"Java",
			"JavaScript",
			"Lisp",
			"Perl",
			"PHP",
			"Python",
			"Ruby",
			"Scala",
			"Scheme"
		];
            $("#tags").autocomplete({
                source: availableTags
            });
        });
    </script>
  
    <%--for keypressed --%>
    <script type="text/javascript">
        function displayunicode(e) {
            var unicode = e.keyCode ? e.keyCode : e.charCode
            alert(unicode)
        }



        function insertTextAtCursor(text) {
            var sel, range, html;
            if (window.getSelection) {
                sel = window.getSelection();
                if (sel.getRangeAt && sel.rangeCount) {
                    range = sel.getRangeAt(0);
                    range.deleteContents();
                    range.insertNode(document.createTextNode(text));
                }
            } else if (document.selection && document.selection.createRange) {
                document.selection.createRange().text = text;
            }
        }
    
    </script>





  
  <div class="panel" style="div.panel">
        </br></br></br></br>
        <asp:Label ID="SpecialityLabel" runat="server" Text="Selecteaza specialitatea"></asp:Label>
        </br>
        <asp:DropDownList ID="SelectSpeciality" runat="server" Width="120px" 
            CausesValidation="True" DataSourceID="DBConnectionString" 
            DataTextField="NumeSpecialitate" DataValueField="NumeSpecialitate" 
            AutoPostBack="True">
              <asp:ListItem Selected="True"></asp:ListItem>
              <asp:ListItem>Spec 1</asp:ListItem>
              <asp:ListItem>Spec 2</asp:ListItem>
              <asp:ListItem>Spec 3</asp:ListItem>
        </asp:DropDownList>

        <asp:SqlDataSource ID="DBConnectionString" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SpecialityDropDownConnectionString %>" 
            SelectCommand="SELECT [ID], [NumeSpecialitate] FROM [DenumiriSpecialitati] ORDER BY [NumeSpecialitate]">
        </asp:SqlDataSource>

        </br></br>
        <asp:CheckBox ID="ModelActive" runat="server" Text="Model Activ" 
            AutoPostBack="True" oncheckedchanged="ModelActive_CheckedChanged" />
        </br>
        
        <asp:Label ID="ModelLabel" runat="server" Text="Selecteaza Modelul"></asp:Label>
        </br>
        <asp:DropDownList ID="SelectModel" runat="server" Width="120px" 
            AutoPostBack="True" Enabled="False" 
            DataSourceID="ModelDropDownConnectionString" DataTextField="NumeModel" 
            DataValueField="NumeModel">
            <asp:ListItem Selected="True"></asp:ListItem>
            <asp:ListItem>Model 1</asp:ListItem>
            <asp:ListItem>Model 2</asp:ListItem>
            <asp:ListItem>Model etc...</asp:ListItem>
        </asp:DropDownList>
 
        <br />
        <br />
        <asp:Label ID="Label3" runat="server" Text="Selecteaza genul"></asp:Label>
        <br />
        <asp:RadioButtonList ID="MFRadioButtonList" runat="server" RepeatLayout="Flow" 
            onselectedindexchanged="MFRadioButtonList_SelectedIndexChanged" 
            AutoPostBack="True">
            <asp:ListItem>Masculin</asp:ListItem>
            <asp:ListItem>Feminin  </asp:ListItem>
            <asp:ListItem Selected="True">Ambele</asp:ListItem>
        </asp:RadioButtonList>

 
        <asp:SqlDataSource ID="ModelDropDownConnectionString" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" 
            SelectCommand="SELECT [ID], [NumeModel], [TextModel], [Specialitate] FROM [DenumiriModele] WHERE ([Specialitate] = @Specialitate)  ORDER BY [NumeModel]">
            <SelectParameters>
                <asp:ControlParameter ControlID="SelectSpeciality" Name="Specialitate" 
                    PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
 
    </div>
    

    <h2>
       
    </h2>
    <div class="multipleWords">

    <h3><asp:Label ID="ModelTextTitle" runat="server" Text="Textul Modelului:" 
            Height="30px" Visible="False"></asp:Label></h3>


        <asp:Panel ID="ModelText" runat="server" ScrollBars="Vertical" Width="777px" 
            Height="190px" BorderColor="#0099FF" BorderWidth="1px" Visible="False">
        <asp:DataList ID="DataList1" runat="server" DataKeyField="ID" 
            DataSourceID="ModelDataSource">
            <ItemTemplate>
                <asp:Label ID="TextModelLabel" runat="server" Text='<%# Eval("TextModel") %>' />
                <br />
            </ItemTemplate>
        </asp:DataList>
        <asp:SqlDataSource ID="ModelDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" 
            SelectCommand="SELECT [ID], [NumeModel], [TextModel], [Specialitate] FROM [DenumiriModele] WHERE (([Specialitate] = @Specialitate) AND ([NumeModel] = @NumeModel))">
            <SelectParameters>
                <asp:ControlParameter ControlID="SelectSpeciality" Name="Specialitate" 
                    PropertyName="SelectedValue" Type="String" />
                <asp:ControlParameter ControlID="SelectModel" Name="NumeModel" 
                    PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        </asp:Panel>
        
         </br>
         <br />
        <h3><asp:Label ID="Label4" runat="server" Text="Textul Generatorului:"></asp:Label></h3>
        <asp:TextBox ID="TextGenerator" runat="server" Width="775px" Height="226px"
            TextMode="MultiLine" ontextchanged="TextGenerator_TextChanged" 
            BorderColor="#0099FF" BorderWidth="1px" ></asp:TextBox>
        &nbsp;
        <br />
        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("ID") %>'></asp:TextBox>
        <br />
        
        <br />
        <input id="Button1" type="button" value="text we've got" onclick="return updateGeneratorAfterNicEdited()" /><br />
<%--        <asp:Button ID="NicEditButton" runat="server" 
            Text="Color Model Text" onclientclick="colorTheModelText()" 
            />--%>

        <input id="Button2" type="button" value="green" onclick="colorTheModelText()" />
        
        
<%--        <asp:Button ID="Button1" runat="server" Text="Stop NIC" 
            onclientclick="stopNicEditor()" />--%>
        <br />
              
        
        
        <textarea id="FinishedText" cols="20" rows="2" 
            style="width: 780px; height: 200px;"></textarea>

         <asp:HiddenField ID="HiddenTextArea" runat="server"/>
         <asp:HiddenField ID="GenreHiddenTextArea" runat="server" />
         <br />
        <br />

        <br />
        <asp:Label ID="Label1" runat="server" Text="" CssClass="boldText">text with bold </asp:Label>
        <asp:Label ID="Label2" runat="server" Text="" CssClass="underlineText">underlined text</asp:Label>
        <br />
        <br />
    </div>
    <div class="demo">
        <div class="ui-widget">
            <label for="tags">
                Tags:
            </label>
            <input id="tags" />
        </div>
    </div>
    <!-- End demo -->
    
    <div id="imHere2" style="position: relative; bottom: 100px"></div>
    <asp:TextBox ID="HiddenTextbox" runat="server" Wrap="False">
        zzz
        <%--aaa--%>
        zzz
    </asp:TextBox>


    <!-- start-stop NicEdit, get browser -->
    <script type="text/javascript">

        function startNicEditor() {
            //removeInstance('FinishedText');
            nic = new nicEditor({ fullPanel: false, iconsPath: 'img/nicEditorIcons.gif', buttonList: ['fontSize', 'fontFamily', 'forecolor', 'bold', 'italic', 'underline', 'strikethrough', 'left', 'center', 'right'], externalCSS: 'Styles/Site.css' })
            .panelInstance('FinishedText', { hasPanel: true });
            nic.addEvent('blur',
                function () {
                    //setting the content from the hidden text area to nicEdit
                    currentEditorText = nicEditors.findEditor('FinishedText').getContent();
                    if (currentEditorText != $("#<%=HiddenTextArea.ClientID%>").val()) {

                        updateGeneratorAfterNicEdited();
                        $("#<%=HiddenTextArea.ClientID%>").val(currentEditorText);

                    }
                });
        }

        function updateGeneratorAfterNicEdited() {

            alert("nicedit text: \n" + "|" + nicEditors.findEditor('FinishedText').getContent() + "|");
            var nicTextTags = nicEditors.findEditor('FinishedText').getContent();
            
            //nicTextTags = nicTextTags.replace(/</, "< ");

            alert("we've got " + browserName );

            switch (browserName) {
                case "Chrome": 
                    {
                        nicTextTags = nicTextTags.replace(/<br>/gi, "");
                        //nicTextTags = nicTextTags.replace(/&nbsp;/gi, "");
                        nicTextTags = nicTextTags.replace(/<div/gi, "998877<div");
                    }
                    break;
                case "Microsoft Internet Explorer": 
                    {
                        nicTextTags = nicTextTags.replace(/&nbsp;/gi, " ");
                        //nicTextTags = nicTextTags.replace(/&nbsp;/gi, "");
                        nicTextTags = nicTextTags.replace(/<p/gi, "998877<p");
                        nicTextTags = nicTextTags.replace(/998877/, "");
                    }
                    break;
                case "Firefox": 
                    {
                        nicTextTags = nicTextTags.replace(/<br/gi, "998877<br");
                        nicTextTags = nicTextTags.replace(/&nbsp;/gi, " ");
                        nicTextTags = nicTextTags.replace(/998877<br>([^998877<br>]*)$/, '$1'); //remove the last <br>, it's redundant
                    }
                    break;
                case "Opera": 
                    {
                        nicTextTags = nicTextTags.replace(/&nbsp;/gi, " ");
                        //nicTextTags = nicTextTags.replace(/<br>/gi, "");
                        nicTextTags = nicTextTags.replace(/<p/gi, "998877<p");
                        nicTextTags = nicTextTags.replace(/998877/, "");
                    }
                    break;
                case "Safari": 
                    {
                        //nicTextTags = nicTextTags.replace(/&nbsp;/gi, "");
                        nicTextTags = nicTextTags.replace(/<div/gi, "998877<div");
                        //nicTextTags = nicTextTags.replace(/998877/, "");
                    }
                    break;
                default:
                    {
                        nicTextTags = nicTextTags.replace(/<p><br>/gi, "<p>");
                        nicTextTags = nicTextTags.replace(/<div/gi, "998877<div"); // 998877 is place holder for future \n
                        nicTextTags = nicTextTags.replace(/<p/gi, "998877<p");
                        nicTextTags = nicTextTags.replace(/<br/gi, "998877<br");
                    }
            }


            alert(nicTextTags);


            $(function () {
                var zxc2 = $("<span>" + nicTextTags + "</span>").text(); //remove html tags
                //alert("the OLD zxc2:" + zxc2);
                zxc2 = zxc2.replace(/998877/gi, "\n");
                //alert("the new zxc2:" + zxc2);

                $("#<%=TextGenerator.ClientID%>").val(zxc2);
                alert(my_function().toString);
            });



        }

        function removeHtmlTagsFromString() { 
        }

        function stopNicEditor() {
            nicEditors.findEditor('FinishedText').removeInstance('FinishedText');
        }

        function startNicEditorOnModel() {
            //removeInstance('FinishedText');
            new nicEditor({ fullPanel: false, iconsPath: 'img/nicEditorIcons.gif', buttonList: [], externalCSS: 'Styles/Site.css' })
            .panelInstance('TextGenerator', { hasPanel: true });
        }

        function refreshNicEditor()
         {
            //removeInstance('FinishedText');
             new nicEditor({ fullPanel: false, iconsPath: 'img/nicEditorIcons.gif', buttonList: ['fontSize', 'fontFamily', 'forecolor', 'bold', 'italic', 'underline', 'strikethrough', 'left', 'center', 'right'], externalCSS: 'Styles/Site.css' })
            .panelInstance('FinishedText', { hasPanel: true });
         }

         function colorTheModelText() {

            temp = "";
            temp = "<font color='green'> " + document.getElementById("MainContent_DataList1_TextModelLabel_0").innerHTML + "</font>";
            document.getElementById("MainContent_DataList1_TextModelLabel_0").innerHTML = temp;
            //document.getElementById('<%=DataList1.ClientID%>').childNodes[0].innerHTML = "-----------";
            document.getElementById('imHere').scrollIntoView(true);

//            Element.prototype.documentOffsetTop = function () {
//                return this.offsetTop + (this.offsetParent ? this.offsetParent.documentOffsetTop() : 0);
//                
//            };

//            var top = document.getElementById("imHere").documentOffsetTop() - (window.innerHeight / 2);
//            
//            window.scrollTo(0, top);

         }


// -->
    </script>


    <!-- AUTOCOMPLETE function -->
      <script type="text/javascript">
          my_function = null;

          var tempString = "";
          currentEditorText = "";
          var tempVar;
          var modelTextOriginal = '';
		  var TagsPlacementArray = new Array();

          try {
              modelTextOriginal = document.getElementById("MainContent_DataList1_TextModelLabel_0").innerHTML;
          } catch (ex) {
          //    alert("NO Model text available"); 
          }


          $(function my_func() {
              $("#<%= TextBox3.ClientID %>").autocomplete({
           

                  source: function (request, response) {
                      $.getJSON("AutoComplete.ashx", {
                          term: extractLast(request.term),
                          gender: function () {
                              //alert(myNicEditor.instanceById("#<%= TextGenerator.ClientID %>"));
                              //alert($("#<%=GenreHiddenTextArea.ClientID%>").val());
                              return $("#<%=GenreHiddenTextArea.ClientID%>").val();
                          }
                      }, response);
                  },
                  search: function () {
                      // custom minLength 
                      var term = extractLast(this.value);
                      if (term.length < 1) {
                          return false;
                      }
                  },
                  focus: function () {
                      // prevent value inserted on focus 
                      return false;
                  },
                  select: function (event, ui) {

                      // split words
                      var terms = splitOnSpace(this.value);
                      termsLastWord = "";

                      // remove the current input 
                      termsLastWord = terms.pop();

                      //search for CRs in last word to remember them
                      if (termsLastWord.match(/\n/gi)) {
                          //                          alert("we have ENTER");
                          termsLastWord = splitOnEnter(termsLastWord);
                          termsLastWord.pop();
                          termsLastWord = termsLastWord.join("\n");
                          termsLastWord += "\n";
                          //                          alert("new last word: '" + termsLastWord + "'");
                          terms.push(termsLastWord);

                      }

                      //search for dots in last word to remember them
                      //alert(termsLastWord);

                      else if (termsLastWord.match(/[.]+/gi)) {
                          //                          alert("we have DOT");
                          termsLastWord = splitOnDot(termsLastWord);
                          termsLastWord.pop();
                          termsLastWord = termsLastWord.join(".");
                          termsLastWord += ".";
                          terms.push(termsLastWord);
                      }


                      tempString = terms;
                      tempString += "";

                      //search for the DOT, first letter in sentence or RETURN key
                      if ((tempString.length == 0) || (tempString.charAt(tempString.length - 1) == ".")
                                                 || (tempString.charCodeAt(tempString.length - 1) == 10)) {
                          t = ui.item.TextAbreviere;
                          //uppercase first letter
                          t = t.charAt(0).toUpperCase() + t.slice(1);
                          alert("word going to NicEdit: |" + t + "|");

                          if ((tempString.length == 0) || (tempString.charCodeAt(tempString.length - 1) == 10))
                              updateNicEditWithP(t + '&nbsp;');
                          else
                              updateNicEditIntoP(t + '&nbsp;');

                          terms.push(t);
                      }
                      else {
                          updateNicEditIntoP(ui.item.TextAbreviere + '&nbsp;');
                          terms.push(ui.item.TextAbreviere);
                      }

                      // add placeholder to get the comma-and-space at the end 
                      terms.push("");
                      //         alert(terms);

                      this.value = terms.join(" ");
                      tempString = this.value;
                      if (modelTextOriginal != "") updateModel(tempString);


                      function updateNicEditWithP(tempString2) {  //word on new line gets br, p , div, etc

                          alert("we've got " + browserName);

                          tempString2 = getTextFormat(tempString2);

                          switch (browserName) {
                              case "Chrome":
                                  {
                                      if (nicEditors.findEditor('FinishedText').getContent() != "")
                                          tempString2 = "<div>" + tempString2 + "</div>";
                                  }
                                  break;

                              case "Microsoft Internet Explorer": { tempString2 = "<p>" + tempString2 + "</p>"; }
                                  break;

                              case "Firefox":
                                  {
                                      if (nicEditors.findEditor('FinishedText').getContent() != "")
                                          tempString2 = "<br>" + tempString2;
                                  }
                                  break;

                              case "Opera": { tempString2 = "<p>" + tempString2 + "</p>"; }
                                  break;

                              case "Safari": { tempString2 = "<div>" + tempString2 + "</div>"; }
                                  break;

                              default: { tempString2 = "<div>" + tempString2 + "</div>"; }
                          }

                          currentEditorText = nicEditors.findEditor('FinishedText').getContent() + tempString2;
                          alert("updateNicEditWithP: |" + tempString2 + "|");
                          nicEditors.findEditor('FinishedText').setContent(currentEditorText);
                          $("#<%=HiddenTextArea.ClientID%>").val(currentEditorText);  //<!--fill hidden text area with current text to save it-->

                      }
                      my_function = my_func;

                      function updateNicEditIntoP(tempString3) {
                          alert("updateNicEditIntoP: |" + tempString3 + "|");
                          //                          tempString2.substr(1, 1);

                          tempString3 = getTextFormat(tempString3);
                          //NU-I BINE CA NU STIU DACA SE TERMINA TEXTU IN NIC HAPT CU TAG-U DE INCHIDERE DE  DIV SAU P SAU BR, ETC
                          currentEditorText = nicEditors.findEditor('FinishedText').getContent();
                          //var textLengt = currentEditorText.length();
                          var textLengt = currentEditorText.length;
                          for (i = 0; i < textLengt; i++) {
                              if (currentEditorText.charAt(textLengt - 1 - i) == "<") {
                                  var lastTag = currentEditorText.substr(textLengt - 1 - i, i + 1);
                                  alert(currentEditorText);
                                  alert("last tag:" + lastTag);
                                  break;
                              }
                          }
                          currentEditorText += tempString3;
                          currentEditorText += lastTag;

                          //currentEditorText = nicEditors.findEditor('FinishedText').getContent() + tempString2;

                          nicEditors.findEditor('FinishedText').setContent(currentEditorText);
                          $("#<%=HiddenTextArea.ClientID%>").val(currentEditorText);  //<!--fill hidden text area with current text to save it-->


                      }


                      function getTextFormat(tempString4) {
                          tempString4 = isTextBold(ui.item.Bold, true) + isTextItalic(ui.item.Italic, true) + getTextSize(ui.item.MarimeText, true)
                                      + tempString4// + '&nbsp;'
                                      + isTextBold(ui.item.Bold, false) + isTextItalic(ui.item.Italic, false) + getTextSize(ui.item.MarimeText, false);

                          //TagsPlacementArray.push();

                          return tempString4;
                      }

                      //                          currentEditorText = nicEditors.findEditor('FinishedText').getContent()
                      //                                      + isTextBold(ui.item.Bold, true) + isTextItalic(ui.item.Italic, true) + getTextSize(ui.item.MarimeText, true)
                      //                                      + tempString2// + '&nbsp;'
                      //                                      + isTextBold(ui.item.Bold, false) + isTextItalic(ui.item.Italic, false) + getTextSize(ui.item.MarimeText, false);

                      //                          nicEditors.findEditor('FinishedText').setContent(currentEditorText);
                      //                          $("#<%=HiddenTextArea.ClientID%>").val(currentEditorText);  //<!--fill hidden text area with current text to save it-->
                      //                     



                      function updateModel(generatorText) {
                          modelTextResult = "";
                          modelTextRed = "<font color='red'>";
                          generatorTextTemp = generatorText.split(" ");
                          generatorTextTemp2 = generatorText.split(" ");

                          // generatorTextTemp.split(" ");
                          //          alert("model active/has text");
                          var s1, s2;
                          do {
                              lastWord = (generatorTextTemp.pop()).toString();
                              lastWordRepetitions = 0;

                              if (lastWord.length > 3) {
                                  //              alert(lastWord.length);

                                  for (i = 0; i < generatorTextTemp2.length - 1; i++) {
                                      s1 = generatorTextTemp2[i].toLowerCase();

                                      try {
                                          //get rid of all the signs(except a few) and keep only the letters in the word
                                          s1 = generatorTextTemp2[i].match(/[A-z]/g).toString();
                                      }
                                      catch (ex) { }

                                      if (s1.toLowerCase() == lastWord.toLowerCase().match(/[A-z]/g).toString()) {
                                          lastWordRepetitions++;
                                      }
                                  }

                                  if (lastWordRepetitions > 0) {

                                      modelText = modelTextOriginal;
                                      modelTextTemp = modelText.split(" ");

                                      for (i = 0; i < modelTextTemp.length; i++) {
                                          s2 = modelTextTemp[i].toLowerCase();
                                          try {
                                              //get rid of all the signs(except a few) and keep only the letters in the word
                                              s2 = modelTextTemp[i].match(/[A-z]/g).toString();
                                          }
                                          catch (ex) { }

                                          if (s2.toLowerCase() == lastWord.toLowerCase().match(/[A-z]/g).toString()) {
                                              lastWordRepetitions--;
                                              if (lastWordRepetitions == 0) {
                                                  //                         alert("color 'till u get here:" + modelTextTemp[i] + " " + modelTextTemp[i + 1]);

                                                  modelTextTemp.splice(i + 1, 0, "</font><div id='imHere' style='position: relative; bottom: 100px'></div>");
                                                  modelTextResult = modelTextRed + modelTextTemp.join(" ");

                                                  document.getElementById("MainContent_DataList1_TextModelLabel_0").innerHTML = modelTextResult;
                                                  document.getElementById('imHere').scrollIntoView(true);

                                                  break;
                                              }
                                          }


                                      }

                                  }

                              }

                          } while (lastWord.length < 4);


                      }


                      //alert(document.getElementById('<%= HiddenTextbox.ClientID %>'));
                      //document.getElementById('<%= TextBox3.ClientID %>').Text = currentEditorText;
                      //$get('<%= HiddenTextArea.ClientID %>').value = currentEditorText;

                      //                  alert($("#<%=HiddenTextArea.ClientID%>").val());

                      //alert(document.getElementById('<%= TextGenerator.ClientID %>').innerHTML.SelectionStart());
                      //window.getSelection().empty();
                      //insertTextAtCursor("----------");alert(window.getSelection());
                      return false;
                  }
              })
            .data("autocomplete")._renderItem = function (ul, item) {
                return $("<li></li>")
				.data("item.autocomplete", item)
				.append("<a>" + item.Abreviere + " : " + item.TextAbreviere + " - " + item.Specialitate + "</a>")
				.appendTo(ul);
            };
              function split(val) {
                  return val.split(/ \s*|\r\n|\r|\n/);
                  //return val.split(" ");
              }
              function splitOnSpaceAndDot(val) {
                  return val.split(/[\s.]+/);
              }
              function splitOnSpace(val) {
                  return val.split(" ");
              }
              function splitOnEnter(val) {
                  return val.split(/\r\n|\r|\n/);
              }
              function splitOnDot(val) {
                  return val.split(".");
              }
              function extractLast(term) {
                  x = splitOnSpaceAndDot(term).pop();
                  //alert("searching:" + x);
                  return x;
              }
          });


          function isTextBold(b, tag) {
              if ((b != "True") && (b != "False")) return "";

              else if (b == "True") {
                  if (tag == true) return "<b>";

                  else return "</b>"
              }
              else if (b == "False") return "";
          }


          function isTextItalic(b, tag) {
              if ((b != "True") && (b != "False")) return "";

              else if (b == "True") {
                  if (tag == true) return "<i>";

                  else return "</i>"
              }
              else if (b == "False") return "";
          }


          function getTextSize(b, tag) {
              if ((b == "") || (b == "NULL") || (b == "null") || (b == "Null") || (b == null) || (b == "False") || (b == "false") || (b == false) || (b == "0") || (b == "undefined") || (b == "UNDEFINED") || (b == "Undefined")) return "";

              else if (tag == true) return "<font size='" + b + "'>";
              else if (tag == false) return "</font>";
          }
   
      </script>




</asp:Content>
